///**
// * 
// */
//package edu.kit.ksri.db.mturk.tests;
//
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.HashSet;
//import java.util.List;
//
//import com.amazonaws.mturk.service.axis.RequesterService;
//import com.amazonaws.mturk.util.PropertiesClientConfig;
//
//import edu.kit.ksri.db.mturk.plugins.correctness.answers.AbstractAssignmentAnswer;
//import edu.kit.ksri.db.mturk.plugins.correctness.answers.AssignmentAnswerFactory;
//import edu.kit.ksri.db.mturk.plugins.correctness.answers.BasicAssignmentAnswer;
//import edu.kit.ksri.db.mturk.plugins.performance.AbstractForecast;
//import edu.kit.ksri.db.mturk.plugins.performance.DummyTimeConstraintsManager;
//import edu.kit.ksri.db.mturk.plugins.performance.ProgressSnapshot;
//import edu.kit.ksri.db.mturk.utils.CSVUtils;
//import edu.kit.ksri.db.mturk.utils.MathUtils;
//import edu.kit.ksri.db.mturk.utils.NumberEvaluation;
//import edu.kit.ksri.db.mturk.utils.numberevaluationhelpers.AbstractInterval;
//import edu.kit.ksri.db.mturk.utils.numberevaluationhelpers.HalfInterval;
//import edu.kit.ksri.db.mturk.utils.numberevaluationhelpers.Interval;
//import edu.kit.ksri.db.mturk.var.StaticInformation;
//import edu.kit.ksri.db.mturk.workerpools.AbstractWorker;
//import edu.kit.ksri.db.mturk.workerpools.PoolManager;
//import edu.kit.ksri.db.mturk.workerpools.StandardWorker;
//import edu.kit.ksri.db.mturk.workerpools.WorkerPool;
//
///**
// * @author David Bermbach
// * 
// * 
// *         created on 24.05.2010
// *         
// */
//public class Testclass {
//	public static void main(String[] args) throws Exception {
//		init();
//		old();
//
//		// PoolManager.getInstance().importWorkers("workers.txt",true);
//		// System.out.println(PoolManager.getInstance().toString());
//		// PoolManager.getInstance().exportWorkers("workers2.txt");
//
//		// testReflections();
//		// testParseAnswer();
//		// testWorkerPools();
//		// doComparisonOfSimulations(new SimpleLinearForecast());
//		// testCSVUtils();
//		// testNumberEvaluation();
//	}
//
//	/**
//	 * 
//	 */
//	private static void testReflections() throws Exception {
//		String answer = "<QuestionFormAnswers xmlns=\"http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd\">"
//				+ "<Answer>    <QuestionIdentifier>some comment field</QuestionIdentifier>    <FreeText>C3</FreeText>  </Answer>  <Answer>    <QuestionIdentifier>likelytowin</QuestionIdentifier>    <SelectionIdentifier>notlikely</SelectionIdentifier>  </Answer></QuestionFormAnswers>";
//		Date d1 = new Date(), d2, d3, d4;
//		AbstractAssignmentAnswer a = AssignmentAnswerFactory
//				.createInstance(answer);
//		AbstractAssignmentAnswer a2 = AssignmentAnswerFactory
//				.createInstance(answer.replace("C3", "C4"));
//		d2 = new Date();
//		System.out.println(a.equals(a2));
//		d3 = new Date();
//		BasicAssignmentAnswer b = AssignmentAnswerFactory
//				.createBasicAssignmentAnswerInstance(answer);
//		BasicAssignmentAnswer b2 = AssignmentAnswerFactory
//				.createBasicAssignmentAnswerInstance(answer.replace("C3", "C4"));
//		System.out.println(b.equals(b2));
//		d4 = new Date();
//		System.out.println("with reflections: " + (d2.getTime() - d1.getTime())
//				+ " ms");
//		System.out.println("no reflections: " + (d4.getTime() - d3.getTime())
//				+ " ms");
//	}
//
//	/**
//	 * 
//	 */
//	private static void testParseAnswer() {
//		String answer = "<QuestionFormAnswers xmlns=\"http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd\">"
//				+ "<Answer>    <QuestionIdentifier>,</QuestionIdentifier>    <FreeText>C3</FreeText>  </Answer>  <Answer>    <QuestionIdentifier>likelytowin</QuestionIdentifier>    <SelectionIdentifier>notlikely</SelectionIdentifier>  </Answer></QuestionFormAnswers>";
//		HashMap<String, String> res = BasicAssignmentAnswer.parseAnswer(answer);
//		System.out.println(res);
//		BasicAssignmentAnswer b1 = new BasicAssignmentAnswer(answer,
//				BasicAssignmentAnswer.IGNORE_NON_PATTERN_ANSWERS);
//		BasicAssignmentAnswer b2 = new BasicAssignmentAnswer(answer.replace(
//				"C3", "C4"), BasicAssignmentAnswer.RAW_ANSWER_IDENTICAL);
//		System.out.println(b1.equals(b2));
//	}
//
//	/**
//	 * 
//	 */
//	private static void testWorkerPools() {
//		WorkerPool wp = PoolManager.getInstance().getPoolForName("ACTIVE");
//
//		wp.addWorker(new StandardWorker("Worker 1", 1));
//		wp.addWorker(new StandardWorker("Worker 2", 0.5));
//		wp.addWorker(new StandardWorker("Worker 3", 0));
//		wp.addWorker(new StandardWorker("Worker 4", -1));
//		wp.addWorker(new StandardWorker("Worker 5", 0.75));
//		wp.addWorker(new StandardWorker("Worker 6", 0.1));
//
//		HashSet<AbstractWorker> temp = PoolManager.getInstance().getPoolForName(
//				"ACTIVE").getBestWorkers(2);
//		for (AbstractWorker w : temp)
//			System.out.println(w.getCorrectnessLevel());
//
//		// PoolManager.getInstance().exportPoolsAsSpaceDelimitedFile("prefix");
//		// PoolManager.getInstance().persist("exported.dat");
//		// PoolManager.getInstance().importFromPersistedFile("exported.dat");
//		// PoolManager.getInstance().exportPoolsAsCSV("prefix");
//	}
//
//	/**
//	 * 
//	 */
//	private static void testNumberEvaluation() {
//		ArrayList<AbstractInterval> intervals = new ArrayList<AbstractInterval>();
//		intervals.add(new HalfInterval(2, true, false));// x<2
//		intervals.add(new Interval(2, 3, false, true));// 2<=x<3
//		intervals.add(new Interval(3, 4, false, false));// 3<=x<=4
//		intervals.add(new Interval(4, 5, true, true));// 4<x<5
//		intervals.add(new Interval(5, 6, false, false));// 5<=x<=6
//		intervals.add(new Interval(6, 7, true, false));// 6<x<=7
//		intervals.add(new Interval(7, 8, true, true));// 7<x<8
//		intervals.add(new HalfInterval(8, false, true));// x>=8
//		NumberEvaluation n = new NumberEvaluation(intervals, 1, 2, 3, 4, 5, 6,
//				7, 8, 9, 10);
//		n.evaluate();
//		System.out.println("max:" + n.getMax());
//		System.out.println("min:" + n.getMin());
//		System.out.println("avg:" + n.getAvg());
//		System.out.println(CSVUtils.toCSVFile(n.getOccurencesByInterval(),
//				"neuertest.csv"));
//
//	}
//
//	/**
//	 * 
//	 */
//	private static void testCSVUtils() {
//		String[][] test = new String[2][2];
//		test[0][0] = "oben links";
//		test[0][1] = "oben rechts";
//		test[1][0] = "unten links";
//		test[1][1] = "unten rechts";
//		String[] captions = new String[3];
//		captions[0] = "1st caption";
//		captions[1] = "2nd caption";
//		captions[2] = "3rd caption";
//		// System.out.println(CSVUtils.toCSVFile(test,captions,"test.csv"));
//		System.out.println(CSVUtils.toCSV(test, captions));
//		Integer[][] i = new Integer[2][2];
//		i[0][0] = 1;
//		i[0][1] = 2;
//		i[1][0] = 3;
//		i[1][1] = 4;
//		System.out.println(CSVUtils.toCSV(CSVUtils.toStringArray(i)));
//
//	}
//
//	/**
//	 * 
//	 */
//	private static void testHeavilyDampedInterpolation() {
//		ArrayList<Double> a = new ArrayList<Double>();
//		for (int i = 0; i < 10; i++) {
//			a.add(i * 1.0);
//		}
//		// System.out.println(new
//		// LinearForecastWithHeavyDamping().getDampedInterpolation(a));
//	}
//
//	/**
//	 * 
//	 */
//	private static void doComparisonOfSimulations(AbstractForecast forecast)
//			throws Exception {
//		double[] percentages = new double[10];
//		for (int i = 0; i < percentages.length; i++) {
//			Calendar end = Calendar.getInstance();
//			end.setTime(new Date());
//			end.add(Calendar.SECOND, 15);
//			DummyTimeConstraintsManager d = new DummyTimeConstraintsManager(end
//					.getTime(), forecast);
//			DummyTimeConstraintsManager.startSimulation(d, 1, 1000, 50, 10,
//					100000, 100, 100, 1);
//			while (!d.isDone())
//				Thread.yield();
//			List<ProgressSnapshot> snaps = d.getSnapshots();
//			int completed = snaps.get(snaps.size() - 1)
//					.getNumberOfAssignmentsCompleted();
//			percentages[i] = completed * 100.0 / 50000;
//		}
//		double avg = 0;
//		for (double d : percentages) {
//			avg += d;
//			System.out.print(d + "%, ");
//		}
//		System.out.println("\navg:" + (avg / percentages.length) + "%");
//		System.out.println("max: " + MathUtils.max(percentages) + "%");
//		System.out.println("min: " + MathUtils.min(percentages) + "%");
//	}
//
//	private static void init() throws Exception {
//		WorkerPool.createNewWorkerPool("ACTIVE", 0);
//		WorkerPool.createNewWorkerPool("PENDING", 0);
//		WorkerPool.createNewWorkerPool("UNKNOWN", 0);
//		WorkerPool.createNewWorkerPool("BLOCKED", 0);
//	}
//
//	public static void old() throws Exception {
//
//		RequesterService rs = new RequesterService(new PropertiesClientConfig(
//				"mturk.properties"));
//
//		// QualificationType qt = rs.createQualificationType(
//		// "QualityControlQualification", "",
//		// "Qualification value is used internally for QM.");
//		// System.out.println(qt.getQualificationTypeId());
//		// Qualification [] qs =
//		// rs.getAllQualificationsForQualificationType(StaticInformation.qualificationTypeID);
//		// for(Qualification q: qs){
//		// System.out.println(q.getSubjectId());
//		// }
//
//		// QualificationRequest [] qrs=
//		// rs.getQualificationRequests(StaticInformation.qualificationTypeID);
//		// for(QualificationRequest q: qrs){
//		// System.out.println(q.getSubjectId());
//		// rs.grantQualification(q.getQualificationRequestId(),
//		// StaticInformation.activePoolQualificationValue);
//		// }
//
//		// rs.disposeQualificationType(StaticInformation.qualificationTypeID);
//		// for(QualificationType q: rs.getAllQualificationTypes())
//		// System.out.println(q.getQualificationTypeId());
//
//		PoolManager.getInstance().importWorkers("real" + StaticInformation.scenario.getPrefix() + "Workers.txt", true);
//		System.out.println("ACTIVE");
//		for (String s : PoolManager.getInstance().getPoolForName("ACTIVE")
//				.getWorkerList()) {
//			Integer score = null;
//			try {
//				score = rs.getQualificationScore(
//						StaticInformation.scenario.getQualificationTypeID(), s)
//						.getIntegerValue();
//			} catch (Exception e) {
//
//			}
//			System.out.println(s + " - " + score);
//		}
//		System.out.println("PENDING");
//		for (String s : PoolManager.getInstance().getPoolForName("PENDING")
//				.getWorkerList()) {
//			Integer score = null;
//			try {
//				score = rs.getQualificationScore(
//						StaticInformation.scenario.getQualificationTypeID(), s)
//						.getIntegerValue();
//			} catch (Exception e) {
//
//			}
//			System.out.println(s + " - " + score);
//		}
//		System.out.println("BLOCKED");
//		for (String s : PoolManager.getInstance().getPoolForName("BLOCKED")
//				.getWorkerList()) {
//			Integer score = null;
//			try {
//				score = rs.getQualificationScore(
//						StaticInformation.scenario.getQualificationTypeID(), s)
//						.getIntegerValue();
//			} catch (Exception e) {
//
//			}
//			System.out.println(s + " - " + score);
//		}
//
//	}
//}
